package com.sike.javacore.serializer.hessian;

import com.caucho.hessian.io.HessianOutput;
import com.sike.javacore.serializer.hessian.dto.Student;
import com.sike.javacore.serializer.hessian.dto.SubStudent;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

public class Hessian04Test {
    public static void main(String[] args) throws IOException {
        SubStudent student = new SubStudent();
        student.setName("李四");
        student.setHeight(185);
        student.setSubValue("lisi");
        student.setGender("男");

        // Hessian 序列化
        ByteArrayOutputStream bos1 = new ByteArrayOutputStream();
        HessianOutput hessianOutput = new HessianOutput(bos1);
        hessianOutput.writeObject(student);
        System.out.println("Hessian 序列化字节流大小：" + bos1.toByteArray().length);

        // Java 原生序列化
        ByteArrayOutputStream bos2 = new ByteArrayOutputStream();
        ObjectOutputStream outputStream = new ObjectOutputStream(bos2);
        outputStream.writeObject(student);
        System.out.println("Java 原生序列化字节流大小：" + bos2.toByteArray().length);
    }
}
